package com.edoomath.api.servcice.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.GenericDaoSupport;
import com.demo2do.core.persistence.annotation.Dao;
import com.edoomath.api.dao.WechatGroupDao;
import com.edoomath.api.servcice.WechatGroupService;
import com.edoomath.entity.course.wechatgroup.WechatGroup;

/**
 * 
 * @author mohanlan
 *
 */
@Service("wechatGroupService")
public class WechatGroupServiceImpl implements WechatGroupService {
    
    @Dao
    private WechatGroupDao wechatGroupDao;
    
    @Autowired
    private GenericDaoSupport genericDaoSupport;
    
    /*
     * (non-Javadoc)
     * @see com.edoomath.api.servcice.WechatGroupService#loadWechatGroup(java.lang.String, java.lang.Long)
     */
    public WechatGroup loadWechatGroup(String opengid, Long courseId) {
    	return wechatGroupDao.load(opengid, courseId);
    }
    
    /*
     * (non-Javadoc)
     * @see com.edoomath.api.servcice.WechatGroupService#loadWechatGroup(java.lang.String)
     */
    public WechatGroup loadWechatGroup(String opengid) {
    	return wechatGroupDao.load(opengid);
    }
    
    /*
     * (non-Javadoc)
     * @see com.edoomath.api.servcice.WechatGroupService#loadWechatGroup(java.lang.Long)
     */
    public WechatGroup loadWechatGroup(Long id) {
    	return wechatGroupDao.load(id);
    }
    
    /*
     * (non-Javadoc)
     * @see com.edoomath.api.servcice.WechatGroupService#search(java.lang.String)
     */
    @SuppressWarnings("unchecked")
    public List<WechatGroup> search(String groupName) {
        return genericDaoSupport.searchForList("FROM WechatGroup group WHERE group.disabled = false AND group.name LIKE '%"+groupName+"%'");
    }
    
    /*
     * (non-Javadoc)
     * @see com.edoomath.api.servcice.WechatGroupService#bindOpengid(com.edoomath.entity.course.wechatgroup.WechatGroup, java.lang.String)
     */
    public void bindOpengid(WechatGroup wechatGroup, String opengid) {
    	genericDaoSupport.update(wechatGroup.bindOpengid(opengid));
    }
}
